package v3

import (
	"encoding/json"
	"gitee.com/delegy/gin-openapi3-knife4go/conf"
	"gitee.com/delegy/gin-openapi3-knife4go/utils"
	"github.com/gin-gonic/gin"
)

const (
	// TODO 路径要改
	SWAGGER_RESOURCES_CONTENT = `{"configUrl": "` + `/v3/api-docs/swagger-config","oauth2RedirectUrl": "` + `/swagger-ui/oauth2-redirect.html","url": "` + `/v3/api-docs","validatorUrl": ""}`

	SWAGGER_RESOURCES_CONFIG_PATH = "/v3/api-docs/swagger-config"
)

func AddSwaggerResourcesRouter(router *gin.Engine) {

	// 需要定义为局部变量，以便relativePath初始化后生效
	var SwaggerResourcesContentJson = map[string]string{
		"configUrl":         conf.GetRelativePath() + "/v3/api-docs/swagger-config",
		"oauth2RedirectUrl": conf.GetRelativePath() + "/swagger-ui/oauth2-redirect.html",
		// 这是api-docs的url。访问时在其前的部分为contextPath
		"url":          "/v3/api-docs",
		"validatorUrl": "",
	}

	SwaggerResourcesContent, err := json.Marshal(SwaggerResourcesContentJson)
	if err != nil {
		panic(err)
	}
	utils.GetJson(router, conf.GetRelativePath()+SWAGGER_RESOURCES_CONFIG_PATH, string(SwaggerResourcesContent))

	//utils.GetJson(router, SWAGGER_RESOURCES_CONFIG_PATH, SWAGGER_RESOURCES_CONTENT)
}
